<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<title>老师个人信息</title>
</head>
<script type="text/javascript">
$(function() {
	//-----------------展现所有学生信息--------------
	$("#allstudentxinxi").datagrid({
		url:'student.json',
		columns:[[   
		          {field:'ck',checkbox:true},
		          {field:'sid',title:'学号',width:100},    
		          {field:'sname',title:'姓名',width:100},    
		          {field:'ssex',title:'性别',width:100},    
		          {field:'sage',title:'年龄',width:100},    
		          {field:'saddress',title:'地址',width:100},    
		          {field:'spnumber',title:'联系电话',width:100},    
		          {field:'stime',title:'入学时间',width:100},    
		          {field:'bid',title:'班级号',width:100},    
		          {field:'bname',title:'班级',width:100}
		      ]] ,
		      rownumbers:true,
		      pagination:true,
		      pagePosition:'bottom',
		      pageSize:10,
		      pageList:[5,10,20],
		      toolbar: [{		      	
 // ----------------------------修改01------------------------------------
		      	iconCls:'icon-edit',
		      	text:'修改学生信息',
		  		handler: function(){
		 //性别下拉框 			
		  			$('#ssex').combobox({ 
		  				editable:false,
					    panelHeight:50
					}); 
		 //入学时间
		  			$('#stime').datebox({ 
			    		editable:false,
		  				width:100   
		  			});  
		  				var  stus = $('#allstudentxinxi').datagrid('getSelections');    
		  				if(stus.length==1){
		  					$("#uptStudent").dialog("open").dialog('setTitle', '修改学生信息'); 
		  					$('#sage').numberbox('setValue',stus[0].sage );
		  					$('#ssex').combobox('setValue',stus[0].ssex );
							$("#sname").textbox('setText',stus[0].sname);
							$("#saddress").val(stus[0].saddress);
							$('#spnumber').numberbox('setValue',stus[0].spnumber );
		//构建班级下拉框
							$('#banji').combobox({
								editable:false,
							    url:'getbanji.json',    
							    valueField:'id',    
							    textField:'text'   
							});
		
							$('#banji').combobox('setValue',stus[0].bid );
		//只能读取日期格式的数据 YYYY-MM-DD
							$('#stime').datebox('setValue', stus[0].stime);
				  					$("#sve").linkbutton({
				  						onClick:function(){					
				  							var sname = $('#sname').textbox('getText');
				  							var sage = $('#sage').numberbox('getValue');
				  							var ssex =$('#ssex').combobox('getText');
				  							var saddress =$("#saddress").val();
				  							var spnumber = $('#spnumber').numberbox('getValue');
				  							var stime =$('#stime').datebox('getText');
				  							var banji =$('#banji').combobox('getText');
				  							var sid =stus[0].sid;
				  							$.ajax({
				  								url:'adminUptStudent',
				  								type:'post',
				  								data:{'sid':sid,'sname':sname,'sage':sage,'ssex':ssex,'saddress':saddress,'spnumber':spnumber,'stime':stime,'banji':banji},
				  								dataType:'text',
				  								success:function(xx){
				  								if(xx=="0"){
				  									$.messager.alert('error','修改失败！','info');
				  								}else{
				  									$.messager.alert('信息','修改成功','info');	
				  									$("#uptStudent").dialog("close");		
				  				     				$('#allstudentxinxi').datagrid('reload');
				  								}}})}})
		  				}else{
		  					$.messager.alert('error','请选择要修改的学生!','info');
		  					$('#allstudentxinxi').datagrid('uncheckAll'); 
		  				}		  				
		  			}
		  	},'-',{
// ----------------------------增加02------------------------------------
				iconCls: 'icon-add',
				text:'增加学生信息',
				handler: function(){
					//设置性别框
					$('#ssex1').combobox({
						editable:false,
					    panelHeight:50
					});
					$('#ssex1').combobox('setText','未选择');
					//设置入学时间框
		  			$('#stime1').datebox({ 
		  				editable:false,
		  				width:100   
		  			}); 
					//加载班级选择框
		  			$('#banji1').combobox({
		  				editable:false,
					    url:'getbanji.json',    
					    valueField:'id',    
					    textField:'text'   
					});
		  			$("#addStudent").dialog("open").dialog('setTitle', '增加学生信息'); 
		  		//---判断增加学生姓名是否填写 ------------
					$("input",$("#sname1").next("span")).blur(function(){	
				 		var sname =$('#sname1').textbox('getText');
						if(sname!=""){
							$("#rsname1").hide();
							$('#sve1').linkbutton('enable');						
		  			$("#sve1").linkbutton({
		  			onClick:function(){	
		  			var uname =$("#uname1")	.val();
		  			var upsw =$("#upsw1").val();
		  			var sname = $("#sname1").val();
		  			var sage = $('#sage1').numberbox('getValue');
		  			var ssex =$('#ssex1').combobox('getText');
		  			var saddress =$("#saddress1").val();
		  			var spnumber = $('#spnumber1').numberbox('getValue');
		  			var banji =$('#banji1').combobox('getText');
		  			var stime =$('#stime1').datebox('getText');

		  			$.ajax({
		  					url:'addStudent',
		  					type:'post',
		  					data:{'uname':uname,'upsw':upsw,'sname':sname,'sage':sage,'ssex':ssex,'saddress':saddress,'spnumber':spnumber,'stime':stime,'banji':banji},
		  					dataType:'text',
		  					success:function(xx){
		  					if(xx=="1"){
		  						$.messager.alert('信息','增加成功','info');
		  						$("#addstu").form('clear');  						
		  						$("#addStudent").dialog("close");		
		  				     	$('#allstudentxinxi').datagrid('reload');
		  					}else{
		  						$.messager.alert('error','增加失败！','info');
		  			}}})}})}else{
						$("#rsname1").show();
						$('#sve1').linkbutton('disable');
					}}); }
		  	},'-',{
// ----------------------------删除03------------------------------------
	      	iconCls:'icon-remove',
	      	text:'删除学生信息',
	  		handler: function(){
	  			var  stus = $('#allstudentxinxi').datagrid('getSelections');  			
	  			
	  			if(stus.length==0){
					$.messager.alert('error','请选择删除的内容！','info');
				}else{
				$("#delStu").dialog("open").dialog('setTitle', '删除学生信息');
				$("#sve2").linkbutton({
					onClick:function(){
				var sids =[];
				for (var i = 0; i < stus.length; i++) {
				sids.push(stus[i].sid);
				}
				$.ajax({
					url:'adminDelStu',
					type:'post',
					data:{'sids':sids},
					dataType:'text',
					success:function(xx){
						if(xx=="0"){
							$.messager.alert('error','删除失败！','info');
							$('#allstudentxinxi').datagrid('reload');
						}else{
							$.messager.alert('信息','删除成功','info');	
							$("#delStu").dialog("close");		
		     				$('#allstudentxinxi').datagrid('reload');
						}}})}})}}
		  	}] 
	});	
//--------------------返回所有学生--------------
$("#fanhui").linkbutton({
			onClick:function(){	
				$('#allstudentxinxi').datagrid('reload');
				$("#allstudentshow").show();
				$("#teastudentshow").hide();
			}
			})
//-----------展现某个老师的学生信息-------------------
	$("#find").linkbutton({
			onClick:function(){	
	$("#allstudentshow").hide();
	$("#teastudentshow").show();
	var tname = $("#tname").val();
	//---判断tname是否存在----
	$.ajax({
		url:'cxteachertname',
		type:'post',
		data:{'tname':tname},
		dataType:'text',
		success:function(xx){

	if(tname==""||xx=="0"){
		$.messager.alert('error','老师不存在！','info');
		$("#allstudentshow").show();
		$("#teastudentshow").hide();
	}else{
	$("#teacherstudentxinxi").datagrid({
		url:'teacherstudent.json',
		queryParams: {
			tname: $("#tname").val()
		},
		columns:[[   
		          {field:'ck',checkbox:true},
		          {field:'sid',title:'学号',width:100},    
		          {field:'sname',title:'姓名',width:100},    
		          {field:'ssex',title:'性别',width:100},    
		          {field:'sage',title:'年龄',width:100},    
		          {field:'saddress',title:'地址',width:100},    
		          {field:'spnumber',title:'联系电话',width:100},    
		          {field:'stime',title:'入学时间',width:100},    
		          {field:'bid',title:'班级',width:100}
		      ]] ,
		      rownumbers:true,
		      pagination:true,
		      pagePosition:'bottom',
		      pageSize:5,
		      pageList:[5,10,20],
		      toolbar: [{		      	
// ----------------------------根据老师修改001------------------------------------
		    	 iconCls:'icon-edit',
		    	 text:'修改学生信息',
		    	 handler: function(){
		    	  //性别下拉框 			
		    	$('#ssex').combobox({ 
		    		editable:false,
		    	 	 panelHeight:50
		    	 }); 
		    	 //入学时间		 
		    	$('#stime').datebox({ 
		    		editable:false,
		    	 width:100   
		    	});  
		    	var  stus1 = $('#teacherstudentxinxi').datagrid('getSelections');    
		    if(stus1.length==1){
		    	 	$("#uptStudent").dialog("open").dialog('setTitle', '修改学生信息'); 
		    	 	$('#sage').numberbox('setValue',stus1[0].sage );
		    	 	$('#ssex').combobox('setValue',stus1[0].ssex );
		    	 	$("#sname").textbox('setValue',stus1[0].sname);
		    	 	$("#saddress").val(stus1[0].saddress);
		    	 	$('#spnumber').numberbox('setValue',stus1[0].spnumber );
		    	//构建班级下拉框
		    	 	$('#banji').combobox({
		    	 		editable:false,
		    	 	url:'getbanji.json',    
		    	 	valueField:'id',    
		    	 	textField:'text'   
		    	 	});
		    	 		
		    	 	$('#banji').combobox('setValue',stus1[0].bid );
		    	//只能读取日期格式的数据 YYYY-MM-DD
		    	 	$('#stime').datebox('setValue', stus1[0].stime);
		    	 	$("#sve").linkbutton({
		    	 	onClick:function(){						
		    	 	var sname = $('#sname').textbox('getText');
		    	 	var sage = $('#sage').numberbox('getValue');
		    	 	var ssex =$('#ssex').combobox('getText');
		    	 	var saddress =$("#saddress").val();
		    	 	var spnumber = $('#spnumber').numberbox('getValue');
		    	 	var stime =$('#stime').datebox('getText');
		    	 	var banji =$('#banji').combobox('getText');
		    	 	var sid =stus1[0].sid;
		    	//请求修改 	
		    	 	$.ajax({
		    	 		  url:'adminUptStudent',
		    	 		  type:'post',
		    	 		  data:{'sid':sid,'sname':sname,'sage':sage,'ssex':ssex,'saddress':saddress,'spnumber':spnumber,'stime':stime,'banji':banji},
		    	 		  dataType:'text',
		    	 		  success:function(xx){
		    	 		  if(xx=="0"){
		    	 		  		$.messager.alert('error','修改失败！','info');
		    	 		  }else{
		    	 		  		$.messager.alert('信息','修改成功','info');	
		    	 		  		$("#uptStudent").dialog("close");		
		    	 		  		$('#teacherstudentxinxi').datagrid('reload');
		    	 		  }}})}})
		    }else{
		    	$.messager.alert('error','请选择要修改的学生!','info');
					$('#teacherstudentxinxi').datagrid('uncheckAll'); 
		    	}}},'-',{
// ----------------------------根据老师增加002------------------------------------
		    	iconCls: 'icon-add',
		    	text:'增加学生信息',
		    	handler: function(){
		    	//设置性别框
		    	$('#ssex1').combobox({ 
		    		editable:false,
		    	 	panelHeight:50
		    	 	});
		    	$('#ssex1').combobox('setText','未选择');
		    	//设置入学时间框
		    	$('#stime1').datebox({
		    		editable:false,
		    		width:100   
		    	 	}); 
		    	//加载班级选择框
		    	$('#banji1').combobox({
		    		editable:false,
		    	 	url:'getbanji.json',    
		    	 	valueField:'id',    
		    	 	textField:'text'   
		    	 	});
		    	//弹出新增窗口
		    	$("#addStudent").dialog("open").dialog('setTitle', '增加学生信息'); 	    	 	  			
		    	//---判断增加学生姓名是否填写 ------------
				$("input",$("#sname1").next("span")).blur(function(){	
			 		var sname =$('#sname1').textbox('getText');
					if(sname!=""){
						$("#rsname1").hide();
						$('#sve1').linkbutton('enable');
		    	$("#sve1").linkbutton({
		    	 	onClick:function(){	
		    	 	var uname =$("#uname1")	.val();
		    	 	var upsw =$("#upsw1").val();
		    	 	var sname = $("#sname1").val();
		    	 	var sage = $('#sage1').numberbox('getValue');
		    	 	var ssex =$('#ssex1').combobox('getText');
		    	 	var saddress =$("#saddress1").val();
		    	 	var spnumber = $('#spnumber1').numberbox('getValue');
		    	 	var banji =$('#banji1').combobox('getText');
		    	 	var stime =$('#stime1').datebox('getText');
				//发送请求
		    	 	$.ajax({
		    	 		url:'addTeacherStudent',
		    	 		type:'post',
		    	 		data:{'uname':uname,'upsw':upsw,'sname':sname,'sage':sage,'ssex':ssex,'saddress':saddress,'spnumber':spnumber,'stime':stime,'banji':banji},
		    	 		dataType:'text',
		    	 		success:function(xx){
		    	 		if(xx=="1"){
		    	 		  	$.messager.alert('信息','增加成功','info');
		    	 		  	$("#addstu").form('clear');
		    	 		  	$("#addStudent").dialog("close");		
		    	 		  	$('#teacherstudentxinxi').datagrid('reload');
		    	 		 }else{
		    	 		  	$.messager.alert('error','增加失败！','info');
		    	 		}}})}})}else{
							$("#rsname1").show();
							$('#sve1').linkbutton('disable');
						}}); }
		    	 		  	},'-',{
 // ----------------------------根据老师删除003------------------------------------
		    	 	      	iconCls:'icon-remove',
		    	 	      	text:'删除学生信息',
		    	 	  		handler: function(){
		    	 	  			var  stus = $('#teacherstudentxinxi').datagrid('getSelections');
		    	 				if(stus.length==0){
		    	 					$.messager.alert('error','请选择删除的内容！','info');
		    	 				}else{
		    	 				$("#delStu").dialog("open").dialog('setTitle', '删除学生信息');
		    	 				$("#sve2").linkbutton({
		    	 					onClick:function(){
		    	 				var sids =[];
		    	 				for (var i = 0; i < stus.length; i++) {
		    	 				sids.push(stus[i].sid);
		    	 				}
		    	 				$.ajax({
		    	 					url:'adminDelStu',
		    	 					type:'post',
		    	 					data:{'sids':sids},
		    	 					dataType:'text',
		    	 					success:function(xx){
		    	 						if(xx=="0"){
		    	 							$.messager.alert('error','删除失败！','info');
		    	 						}else{
		    	 							$.messager.alert('信息','删除成功','info');	
		    	 							$("#delStu").dialog("close");		
		    	 		     				$('#teacherstudentxinxi').datagrid('reload');
		    	 							}}})}})}}
		    	 		  	}] 
	});
	}}})}
	})

//判断修改学生年龄在0——150之间
	$("input",$("#sage").next("span")).blur(function(){
		var sage = $('#sage').numberbox('getValue');
		if(sage<=0||sage>=150){
		    	$("#rsage").show();	    	
		}else{
			$("#rsage").hide();
		}
	    });
//判断修改学生电话号码是否正确
	$("input",$("#spnumber").next("span")).blur(function(){
		var spnumber =  $('#spnumber').numberbox('getValue');
		if(spnumber<=10000000000||spnumber>=19999999999){
		    	$("#rspnumber").show();
		}else{
			$("#rspnumber").hide();
		}
	    })
//判断新增学生年龄在0——150之间
		$("input",$("#sage1").next("span")).blur(function(){
			var sage = $('#sage1').numberbox('getValue');
			if(sage<=0||sage>=150){
			    	$("#rsage1").show();
			}else{
				$("#rsage1").hide();
			}
		    });
//判断新增学生电话号码是否正确
	$("input",$("#spnumber1").next("span")).blur(function(){
		var spnumber =  $('#spnumber1').numberbox('getValue');
		if(spnumber<=10000000000||spnumber>=19999999999){
		    	$("#rspnumber1").show();
		}else{
			$("#rspnumber1").hide();
		}
	    });

//---判断新增学生用户名是否填写---用户是否存在-------
	$("input",$("#uname1").next("span")).blur(function(){	
 		var uname =$('#uname1').textbox('getText');
		if(uname==""){
			$("#runame1").show();
	}else{
			 $.ajax({
				 url:'cxuname',
				 type:'post',
				 data:{'uname2':uname},
				 datatype:'text',
				 success:function(data){
					 if(data=="1"){
						$("#runame1").show();
					 }else{
						 $("#runame1").hide();
					 }
				 } 
			 })
		$("#runame1").hide();
	}}); 
//-------批量导入-----------
		$("#into").linkbutton({
			onClick:function(){	
		 var dress = $("#dress").val();
		 		$.ajax({
					url:'insertstudentsss',
					type:'post',
					data:{'dress':dress},
					dataType:'text',
					success:function(xx){
						if(xx=="1"){
						$.messager.alert('messager','增加成功','info');
						$('#allstudentxinxi').datagrid('reload');
						}else{
							$.messager.alert('error','增加失败','info');
							$('#allstudentxinxi').datagrid('reload');
						}
					}
				})
			}
		});
})
</script>
<body>

<!-----------------老师姓名输入框  -------------->
<div>
<span style="font-size: x-small;">按老师姓名或编号查找</span><input id="tname" name="tname" class="easyui-validatebox"  />
<button id="find"  class="easyui-linkbutton" >搜索</button>
</div>

<!----------------展现所有学生信息 ----------->
<div id="allstudentshow"  style="display:block;">
<table id="allstudentxinxi" >
</table>
</div> 
<!----------------- 根据查找老师姓名学生--------------->
<div id="teastudentshow" style="display:none;">
<button id="fanhui"  class="easyui-linkbutton" >返回查看所有学生信息</button>
<table id="teacherstudentxinxi" >
</table>
</div> 

<!------------------------------------- 修改窗口 ----------------------------------------->
<div id="uptStudent" class="easyui-dialog"  closed="true" buttons="#dlg1-buttons "  > 
		<div  style="width: 300px;height: 250px;margin-top: 50px;margin-left:80px">
              姓名<input id="sname" name="sname" class="easyui-textbox"  />
          <span id="rsname"  style="font-size:xx-small; display:none; ">请输入姓名!</span><br>    
              年龄<input id="sage" name="sage"  class="easyui-numberbox"  data-options="precision:0"/>
		<span id="rsage"  style="font-size:xx-small;display:none;">年龄在0—150岁之间!</span><br>
              性别<select id="ssex" class="easyui-combobox" name="ssex" style="width:70px;">   
    <option value="请选择">男</option>   
    <option>女</option> 
</select><br>
               地址<input id="saddress" name="saddress" class="easyui-validatebox"  /><br>
               电话<input id="spnumber" name="spnumber" class="easyui-numberbox"  data-options="precision:0" />
           <span id="rspnumber"  style="font-size:xx-small;display:none;">请输入正确的电话号码!</span><br>
               班级<input id="banji" name="banji"  style="width:100px;"><br>              
            入学时间<input id="stime" name="stime" class="easyui-datebox"  style="width:150px;"/> <br>   
      </div>
       <div id="dlg1-buttons">
        <button id="sve"  class="easyui-linkbutton"  iconcls="icon-save">确认修改</button>
        <a id="cancl0" class="easyui-linkbutton" onclick="javascript:$('#uptStudent').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
</div>
<!------------------------------------- 增加窗口----------------------------------------->
<div id="addStudent" class="easyui-dialog" closed="true"  buttons="#dlg2-buttons "  > 
		 <form id="addstu">
		 <div  style="width: 300px;height: 250px;margin-top: 50px;margin-left:80px">
              用户名<input id="uname1"  class="easyui-textbox" required="true"/>
             <span id="runame1"  style="font-size:xx-small; display:none; ">请输入用户名/用户已存在!</span><br>        
              密&nbsp;&nbsp;&nbsp;码<input id="upsw1"  class="easyui-numberbox"  data-options="precision:0" type="password" />
              <span id="rupsw1"  style="font-size:xx-small; display:none; ">密码为6位数字!</span><br>
              姓&nbsp;&nbsp;&nbsp;名<input id="sname1"  class="easyui-textbox" required="true"/>
              <span id="rsname1"  style="font-size:xx-small; display:none; ">请输入姓名!</span><br>     
              年&nbsp;&nbsp;&nbsp;龄<input id="sage1"  class="easyui-numberbox"  data-options="precision:0"/>
		<span id="rsage1"  style="font-size:xx-small;display:none;">年龄在0—150岁之间!</span><br>
              性&nbsp;&nbsp;&nbsp;别<select id="ssex1" class="easyui-combobox"  style="width:70px;">   
    <option>男</option>   
    <option>女</option> 
    </select><br>
               地&nbsp;&nbsp;&nbsp;址<input id="saddress1" class="easyui-validatebox"  /><br>
               电&nbsp;&nbsp;&nbsp;话<input id="spnumber1" class="easyui-numberbox"  data-options="precision:0" />
               <span id="rspnumber1"  style="font-size:xx-small;display:none;">请输入正确的电话号码!</span><br>
               班&nbsp;&nbsp;&nbsp;级<input id="banji1" name="banji1"  value="一班" style="width:100px;">
               <span id="rsbanji1"  style="font-size:xx-small;display:none;">请选择班级!</span><br>    
               入学时间<input id="stime1" class="easyui-datebox"  style="width:150px;"/> <br>    
        </div>
        </form>
        <div id="dlg2-buttons">
        <button id="sve1"  class="easyui-linkbutton"  iconcls="icon-save">确认增加</button>
        <a id="cancl1" class="easyui-linkbutton" onclick="javascript:$('#addStudent').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
</div>
<!------------------------------------- 删除窗口 ----------------------------------------->
<div id="delStu" class="easyui-dialog"  closed="true" buttons="#dlg3-buttons "  > 
	<div  style="width: 300px;height: 250px;margin-top: 50px;margin-left:80px">
			<h5 style="font-size: medium;">请谨慎删除！</h5>
		</div>
       <div id="dlg3-buttons">
        <button id="sve2"  class="easyui-linkbutton"  iconcls="icon-save">确认删除</button>
        <a id="cancl2" class="easyui-linkbutton" onclick="javascript:$('#delStu').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
</div>
</body>
</html>